<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ page import="com.hzqy.commons.utils.ConstantUtils" %>
<%@ taglib prefix="limits" uri="/WEB-INF/tld/limits.tld"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>角色</title>
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/defalut.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/public.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/ddspstyle.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/icon.css">
<script type="text/javascript" src="../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../static/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="../static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../static/js/index.js"></script>
<%
String []nonceObj=ConstantUtils.getNonceObject();
%>
<script type="text/javascript">
		var queryParams;
		function EasyuiDatagrid() {
			$("#easyui-datagrid").datagrid({
				url: 'role_list.do',
				nowrap: true,
				striped: true,
				border: false,
				fit: true,
				rownumbers:true,
				queryParams: getGueryParams(),
				columns: [[
					{field:'f_prole_id',checkbox:true},
					{field:'f_prole_name',title:'角色名称',align:'center',width:150},
					{field:'f_prole_desc',title:'简介',align:'center',width:150},
					{field:'f_prole_status',title:'状态',align:'center',width:150,
						formatter:function(value,row,index) {
							var status = "未知";
							if(value==1){
								status="有效";
							} else if(value==2){
								status="无效";
							} else {
								status="未知";
							}
							return status;
						}	
					},
					{field:'f_prole_createAt',title:'添加时间',align:'center',width:150},
					{field:'f_prole_updateAt',title:'修改时间',align:'center',width:150},
					{field:'_parentId',title:'操作',align:'center',width:200,
						formatter:function(value,row,index){
							str ="";
							str= '<limits:uiAuth url="del_role.do"><a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="onClickBtnDelete(\''+row.f_prole_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-remove l-btn-icon-left">删除</span></span></a></limits:uiAuth>';
							str+= '<limits:uiAuth url="role_edit.jsp"><a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="edit(\''+row.f_prole_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-edit l-btn-icon-left">修改</span></span></a></limits:uiAuth>';
				    		str+= '<limits:uiAuth url="role_authorize.jsp"><a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="show(\''+row.f_prole_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-search l-btn-icon-left">授权</span></span></a></limits:uiAuth>';
					    	return str;
				    	}
					}
				]],
				singleSelect:false,
				pagination:true,
				pageList:[10,20,30,40,50],
				pageSize:10,
				toolbar: '#toolbar',
				
				onExpandRow: function(index,row){
				
				},
				onSelect: function(rowIndex,rowData) {
					
				},
				onUnselect: function(rowIndex,rowData) {
					
				},
				onCheckAll: function(rowIndex,rowData) {
					
				},
				onUncheckAll: function(rowIndex,rowData) {
				
				},
				onLoadSuccess: function(data) {
					if(data.total==-1) {
						$.messager.defaults={ok:"确定",cancel:"取消"};
						$.messager.confirm('提示', '用户尚未登录,请登录', function(r){
						if (r){
						    window.parent.location.href='/index.jsp';
						    return false;
						}});
					}
				}
			});
		}
	
		function getGueryParams(){
			return {
				f_prole_name:$("#f_prole_name").val(),
				f_prole_status:$("#f_prole_status").val()
			};
		}
		
		$(function(){
			new EasyuiDatagrid();
			gotoSearch = function(){
				$("#easyui-datagrid").datagrid('reload',getGueryParams());
			};
			
			onClickBtnDelete = function(id){
				$.messager.confirm('确定删除角色','确定删除角色么?',function(r){
					if(r){
						app_ajax('del_role.do?f_prole_id='+id+'&stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>',
						'',
						function(msg){
							if(msg.success) {
								alert("删除成功!");
								if (checkAjaxRequestValidity(msg)) {
									gotoSearch($('#easyui-treegrid'));
								}
							} else {
								alert("删除异常，请联系管理员");
								if($.isFunction(window.showMessager)){
									window.showMessager(msg.resultTitle,msg.result);
								}
							}
							window.location.reload();
						}
						);
					}
				});
			};
		});
		
		function SubgridTabOnSelect(title,index){
			setTimeout(function(){
				$("#easyui-datagrid").datagrid('fixDetailRowHeight',index);
			},300);
			setTimeout(function(){
				$("#easyui-datagrid").datagrid('fixDetailRowHeight',index);
			},3000);
	    }
		
		function load(){
			$(".datagrid-row-expander datagrid-row-expand").attr("display","none"); 
		}
		
		function _resert(){
			$("#f_prole_name").val("");
			$("#f_prole_status").val("");
		}
		
		function onpress(){
			var event=arguments.callee.caller.arguments[0]||window.event;//消除浏览器差异
	   		  	if (event.keyCode == 13){  
	      			gotoSearch($('#easyui-treegrid'));
	    		}
		}
		
		function edit(id){
			openDialog($("#dlg"),'role_edit.jsp?f_prole_id='+id);
		}
		
		function show(id){
			openDialog($('#dlg'),'role_authorize.jsp?f_prole_id='+id);
		}
		
		function add(){
			openDialog($('#dlg'),'role_add.jsp');
		}
	</script>
</head>
<body onload="load();">
	<table id="easyui-datagrid" title="角色列表"></table>
	<div id="toolbar" class="easyui_datagrid_toolbar" style="">
		<div class="easyuiSearch">
			<form onsubmit="return false;" method="post">
				<table cellspacing="0" cellpadding="0" width="90%">
					<tr>
						<td align="right" width="10%">角色名称：</td>
						<td align="left" width="25%"><input name="f_prole_name"
							id="f_prole_name" style="width: 150px;" onkeydown="onpress();" /></td>
						<td align="right" width="10%">角色状态：</td>
						<td align="left" width="25%"><select id="f_prole_status"
							name="f_prole_status">
								<option value="0">请选择</option>
								<option value="1">有效</option>
								<option value="2">无效</option>
						</select></td>
						<td align="left" width="15%"><limits:uiAuth
								url="role_list.do">
								<a href="javascript:void(0);" class="easyui-linkbutton"
									data-options="iconCls:'icon-search', plain:true"
									onclick="gotoSearch($('#easyui-datagrid'))">查询</a>
							</limits:uiAuth></td>
						<td align="left" width="15%"><limits:uiAuth
								url="role_add.jsp">
								<a href="javascript:void(0);" class="easyui-linkbutton"
									data-options="iconCls:'icon-add', plain:true" onclick="add()">增加角色</a>
							</limits:uiAuth></td>
					</tr>
				</table>
			</form>
		</div>
		<div style="margin-bottom: 5px">
			<!-- <a href="javascript:void(0)" class="easyui-linkbutton" onclick="delete();" iconCls="icon-cut" plain="true">删除</a>  -->
		</div>
	</div>
	<div id="dlg" class="easyui-dialog"
		style="width: 600px; height: 470px; padding-top: 0px;"
		data-options="title:'角色详情', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
		<iframe scrolling="auto" frameborder="0"
			style="width: 100%; height: 99%;"></iframe>
	</div>
</body>
</html>